package com.t.bricks.bussiness.controller.nas;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.t.bricks.bussiness.service.nas.NasService;
import com.t.bricks.model.MsgEmity;

@RestController
@Api(value = "网络附属存储", tags = { "网络附属存储操作接口" })
@RequestMapping("/nas/")
public class NasController {
	
	@Autowired
	private NasService nasService;

	/**
	 * 文件上传
	 * @param file 文件
	 * @return
	 */
	//[start]
	@ApiOperation(value="文件上传")
//	@ApiImplicitParams({
//		@ApiImplicitParam(name="file", value="文件", dataType="MultipartFile", paramType="body", required=true)
//	})
	@ApiResponses({
		@ApiResponse(code=200, message="{\"success\": 布尔值, \"msg\": 文字提示, \"data\": 码值}"),
		@ApiResponse(code=400, message="错误的请求,请检查路径"),
		@ApiResponse(code=404, message="请求路径没有或页面跳转路径不对"),
		@ApiResponse(code=1000001, message="内部请求密钥错误"),
		@ApiResponse(code=1000002, message="您还没有登录或登录已超时,需要重新登录"),
		@ApiResponse(code=1000003, message="检查登录状态失败,请稍后重试！"),
		@ApiResponse(code=1000004, message="请求的操作不存在,请检查访问地址正确性，如大小写"),
		@ApiResponse(code=1000005, message="响应后在系统内部发生不可预知的错误"),
		@ApiResponse(code=1019000, message="1019000~1999999为拦截器调用方法错误"),
		@ApiResponse(code=6001, message="上传文件为空"),
		@ApiResponse(code=6002, message="上传文件发生异常"),
		@ApiResponse(code=6999, message="上传成功!")
	})
	//[end]
	@RequestMapping(method={ RequestMethod.POST, RequestMethod.GET }, value="/upload")
	public MsgEmity upload(@RequestParam("file") MultipartFile file) {
		return nasService.upload(file);
	}

	/**
	 * 文件下载
	 * @param filePath
	 * @return
	 */
	//[start]
	@ApiOperation(value="文件下载")
	@ApiImplicitParams({
		@ApiImplicitParam(name="filePath", value="文件相对路径", dataType="String", paramType="query", required=true)
	})
	@ApiResponses({
		@ApiResponse(code=200, message="{\"success\": 布尔值, \"msg\": 文字提示, \"data\": 码值|文件}"),
		@ApiResponse(code=400, message="错误的请求,请检查路径"),
		@ApiResponse(code=404, message="请求路径没有或页面跳转路径不对"),
		@ApiResponse(code=1000001, message="内部请求密钥错误"),
		@ApiResponse(code=1000002, message="您还没有登录或登录已超时,需要重新登录"),
		@ApiResponse(code=1000003, message="检查登录状态失败,请稍后重试！"),
		@ApiResponse(code=1000004, message="请求的操作不存在,请检查访问地址正确性，如大小写"),
		@ApiResponse(code=1000005, message="响应后在系统内部发生不可预知的错误"),
		@ApiResponse(code=1019000, message="1019000~1999999为拦截器调用方法错误"),
		@ApiResponse(code=8001, message="请求参数为空"),
		@ApiResponse(code=8002, message="请求越界"),
		@ApiResponse(code=8003, message="文件不存在"),
		@ApiResponse(code=6001, message="文件不存在"),
		@ApiResponse(code=6002, message="获取当前线程Response失败"),
		@ApiResponse(code=6003, message="设置文件下载头信息发生异常"),
		@ApiResponse(code=6004, message="读取文件发生异常"),
		@ApiResponse(code=6005, message="关闭输出流发生异常"),
		@ApiResponse(code=6006, message="关闭文件流发生异常"),
		@ApiResponse(code=6999, message="文件下载成功")
	})
	//[end]
	@RequestMapping(method={ RequestMethod.POST, RequestMethod.GET }, value="/download")
	public MsgEmity download(String filePath) {
		return nasService.download(filePath);
	}

	/**
	 * 指定目录下的文件列表
	 * @param 目录
	 * @param findAll 是否递归获取
	 * @param killRootPath 要去除的路径前缀
	 * @return
	 */
	//[start]
	@ApiOperation(value="指定目录下的文件列表")
	@ApiImplicitParams({
		@ApiImplicitParam(name="dir", value="目录", dataType="String", paramType="query", required=true),
		@ApiImplicitParam(name="findAll", value="是否查询子目录(1:是)", dataType="Inteer", paramType="query", required=false)
	})
	@ApiResponses({
		@ApiResponse(code=200, message="{\"success\": 布尔值, \"msg\": 文字提示, \"data\": 码值|Json集合}"),
		@ApiResponse(code=400, message="错误的请求,请检查路径"),
		@ApiResponse(code=404, message="请求路径没有或页面跳转路径不对"),
		@ApiResponse(code=1000001, message="内部请求密钥错误"),
		@ApiResponse(code=1000002, message="您还没有登录或登录已超时,需要重新登录"),
		@ApiResponse(code=1000003, message="检查登录状态失败,请稍后重试！"),
		@ApiResponse(code=1000004, message="请求的操作不存在,请检查访问地址正确性，如大小写"),
		@ApiResponse(code=1000005, message="响应后在系统内部发生不可预知的错误"),
		@ApiResponse(code=1019000, message="1019000~1999999为拦截器调用方法错误"),
		@ApiResponse(code=8001, message="请求参数为空"),
		@ApiResponse(code=8002, message="请求越界"),
		@ApiResponse(code=8003, message="目录不存在")
	})
	//[end]
	@RequestMapping(method={ RequestMethod.POST, RequestMethod.GET }, value="/list")
	public MsgEmity getlist(String dir, Integer findAll) {
		return nasService.getlist(dir, "1".equals(findAll));
	}
	
}
